package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.model.ArrivalDateUpdate;
import com.chinairi.mall.service.IArrivalDateUpdateService;
import com.chinairi.mall.service.modelobject.ArrivalDateUpdateMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 董志涵
 * @since 2020-10-21
 */
@RestController
@RequestMapping("/arrival-date-update")
public class ArrivalDateUpdateController extends BaseController {
    @Autowired
    private IArrivalDateUpdateService iArrivalDateUpdateService;


    /**
     * 新增修改到货日期
     * @param arrivalDateUpdate
     */
    @PostMapping("/add")
    public void add(@RequestBody ArrivalDateUpdate arrivalDateUpdate) throws IOException {
        iArrivalDateUpdateService.add(arrivalDateUpdate);
        ResponseUtil.showMessage("success", "新增成功", "");
    }

    /**
     * 修改 修改到货日期
     * @param arrivalDateUpdate
     */
    @PostMapping("/update")
    public void update(@RequestBody ArrivalDateUpdate arrivalDateUpdate) throws IOException {
        iArrivalDateUpdateService.update(arrivalDateUpdate);
        ResponseUtil.showMessage("success", "新增成功", "");
    }

    /**
     * 修改 处理标志位
     * @param arrivalDateUpdate
     */
    @GetMapping("/updateFlag")
    public void updateFlag(ArrivalDateUpdate arrivalDateUpdate) throws IOException, ParseException {
        iArrivalDateUpdateService.updateFlag(arrivalDateUpdate);
        ResponseUtil.showMessage("success", "处理成功", "");
    }

    /**
     * 买家用户获取修改到货日期的待办
     * @throws IOException
     * @throws ParseException
     */
    @GetMapping("/getByReceiverId")
    public void getByReceiverId() throws IOException, ParseException {
        List<ArrivalDateUpdateMO> arrivalDateUpdateList = iArrivalDateUpdateService.getByReceiverId();
        ResponseUtil.showMessage("success", "处理成功", arrivalDateUpdateList);
    }

    /**
     * 自动更新到期的待办的状态
     * @throws IOException
     * @throws ParseException
     */
    @Scheduled(cron = "0 0 23 * * ?")
    @GetMapping("/updateFlagAuto")
    public void updateFlagAuto() throws IOException, ParseException {
        iArrivalDateUpdateService.updateFlagAuto();
        ResponseUtil.showMessage("success", "处理成功", "");
    }

    /**
     * 买家调整到货日期后修改
     * @throws IOException
     * @throws ParseException
     */
    @GetMapping("/updateDate")
    public void updateDate(String aduId) throws IOException, ParseException {
        iArrivalDateUpdateService.updateDate(aduId);
        ResponseUtil.showMessage("success", "处理成功", "");
    }

    /**
     * 买家新增修改到货日期提醒
     * @param arrivalDateUpdate
     */
    @PostMapping("/addRemind")
    public void addRemind(@RequestBody ArrivalDateUpdate arrivalDateUpdate) throws IOException {
        iArrivalDateUpdateService.addRemind(arrivalDateUpdate);
        ResponseUtil.showMessage("success", "新增成功", "");
    }

    /**
     * 卖家用户获取修改到货日期的提醒
     * @throws IOException
     * @throws ParseException
     */
    @GetMapping("/getRemindByShopId")
    public void getRemindByShopId() throws IOException, ParseException {
        List<ArrivalDateUpdateMO> arrivalDateUpdateList = iArrivalDateUpdateService.getRemindByShopId();
        ResponseUtil.showMessage("success", "处理成功", arrivalDateUpdateList);
    }
}
